
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>权限组管理</title>
    {include file="include/top"}
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-inline">
                <label class="layui-form-label">组筛选</label>
                <div class="layui-input-inline">
                    <select name="group">
                        <option value="">项目筛选</option>
                        <?php foreach ($zu as $v){?>
                        <option value="{$v.id}">{$v.title}</option>
                        <?php }?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名</label>  
                <div class="layui-input-inline">
                    <input type="text" name="fullname" value="" placeholder="支持模糊搜索" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">属性</label>
                <div class="layui-input-inline">
                    <select name="yincang">
                        <option value="1">正常</option>
                        <option value="2">隐藏</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
        <div class="layui-card-header layuiadmin-card-header-auto">
            <button type="button" class="layui-btn" id="test-upload-type1" data-imgid="adduser"><i class="layui-icon"></i>添加用户</button>
        </div>
        <table class="layui-table" lay-data="{height:0, url:'/adminauth/userlist', page:true, id:'idTest' ,cellMinWidth: 80}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox'}"></th>
                <th lay-data="{field:'id',  sort: true, width:80}">ID</th>
                <th lay-data="{field:'username'}">账号</th>
                <th lay-data="{field:'fullname'}">姓名</th>
                <th lay-data="{field:'phone'}">电话</th>
                <th lay-data="{field:'ctype',templet:function(d){
                    if(d.ctype==1){
                        return '服务商业务';
                    }else if(d.ctype==0){
                        return '系统管理';
                    }
                }}">角色</th>
                <th lay-data="{field:'status',templet:function(d){
                    if(d.status==1){
                        return '正常';
                    }else if(d.status==-1){
                        return '失效';
                    }
                }}">状态</th>
                <th lay-data="{ align:'center', toolbar: '#barDemo',width:180}"></th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-xs" lay-event="auth">权限</a>
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edituser">修改</a>
        </script>
    </div>
</div>
{include file="include/js"}
<script>
    var pathid=0;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table'], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var pathid=0;
        var id=0;
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('idTest', {
                where: field,page:{curr:1}
            });
        });
        $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $("#test-upload-type1").click(function () {
            layer.open({
                type: 2
                ,title: '添加用户'
                ,content: 'adduser'
                ,btn: ['确定', '取消']
                ,area: ['100%', '80%']
                ,yes: function(index, layero){
                    layer.confirm('是否确定添加?', {icon: 3, title:'提示'}, function(index){
                        //do something
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
                            ,username = othis.find('input[name="username"]').val()
                            ,fullname = othis.find('input[name="fullname"]').val()
                            ,password = othis.find('input[name="password"]').val()
                            ,password2 = othis.find('input[name="password2"]').val()
                            ,phone = othis.find('input[name="phone"]').val()
                            ,address = othis.find('input[name="address"]').val()
                            ,company = othis.find('input[name="company"]').val()
                            ,email = othis.find('input[name="email"]').val()
                            ,serviceIDS = othis.find('input[name="serviceIDS"]').val()
                            ,yincang = othis.find('select[name="yincang"]').val()
                            ,ctype = othis.find('select[name="ctype"]').val()
                        $.post("adduserpost",{username:username,fullname:fullname,password:password,password2:password2,address:address,phone:phone,company:company,email:email,yincang:yincang,serviceIDS:serviceIDS,ctype:ctype},function (re) {
                            layer.msg(re.msg);
                            setTimeout(function () {
                                location.reload();
                            },2000);
                        },'json');
                        layer.close(index);
                    });
                }
            });
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'admin'){
                id=data.id;
                layer.open({
                    type: 2
                    ,title: '角色管理'
                    ,content: 'juese?uid='+data.id
                    ,btn: ['确定', '取消']
                    ,area: ['400px', '400px']
                    ,yes: function(index, layero){
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
                            ,like = [];
                        othis.find('input[type="checkbox"]').each(function () {
                            if($(this).is(":checked")){
                                like.push($(this).attr("name"));
                            }
                        });
                        $.post("/adminauth/juesebaocun",{like:like,id:id,},function (re) {
                            layer.msg(re.msg);
                            if(re.code==0){
                                setTimeout(function () {
                                    location.reload();
                                },2000);
                            }
                        },'json');
                    }
                });
            } else if(obj.event === 'edit'){
                id=data.id;
                // layer.alert('编辑行：<br>'+ JSON.stringify(data))
                $.post("/adminauth/task",{id:id},function (re) {
                    layer.msg(re.msg,function () {
                        if(re.code==0){
                            window.open("/project/list","_self")
                        }
                    });

                },'json');
            } else if(obj.event === 'edituser'){
                id=data.id;
                layer.open({
                    type: 2
                    ,title: '添加用户'
                    ,content: 'adduser?uid='+id
                    ,btn: ['确定', '取消']
                    ,area: ['100%', '80%']
                    ,yes: function(index, layero){
                        layer.confirm('是否确定添加?', {icon: 3, title:'提示'}, function(index){
                            //do something
                            var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
                                ,username = othis.find('input[name="username"]').val()
                                ,fullname = othis.find('input[name="fullname"]').val()
                                ,pathid = othis.find('input[name="pathid"]').val()
                                ,pathid2 = othis.find('input[name="pathid2"]').val()
                                ,password = othis.find('input[name="password"]').val()
                                ,password2 = othis.find('input[name="password2"]').val()
                                ,phone = othis.find('input[name="phone"]').val()
                                ,address = othis.find('input[name="address"]').val()
                                ,company = othis.find('input[name="company"]').val()
                                ,email = othis.find('input[name="email"]').val()
                                ,serviceIDS = othis.find('input[name="serviceIDS"]').val()
                                ,yincang = othis.find('select[name="yincang"]').val()
                                ,ctype = othis.find('select[name="ctype"]').val()
                            $.post("adduserpost",{pathid:pathid,pathid2:pathid2,username:username,fullname:fullname,password:password,password2:password2,uid:id,phone:phone,address:address,company:company,email:email,yincang:yincang,serviceIDS:serviceIDS,ctype:ctype},function (re) {
                                layer.msg(re.msg);
                                setTimeout(function () {
                                    location.reload();
                                },2000);
                            },'json');
                            layer.close(index);
                        });
                    }
                });
            }else if(obj.event === 'auth'){
                // layer.alert('编辑行：<br>'+ JSON.stringify(data))
                window.open("/adminauth/authgroup?uid="+data.id,"_self");
            }else if(obj.event=='qrcode'){
                id=data.id;
                // layer.alert('编辑行：<br>'+ JSON.stringify(data))let bytes = new Uint8Array(data);


                $.post("/adminauth/qrcode",{id:id},function (re) {
                    if(re.code==0){
                        layer.alert("<img src='/"+re.data.img+"' width='200px'>");
                    }else{
                        layer.msg("获取失败");
                    }

                },'json');
            }
            function arrayBufferToBase64(buffer) {
                var binary = '';
                var bytes = new Uint8Array(buffer);
                var len = bytes.byteLength;
                for (var i = 0; i < len; i++) {
                    binary += String.fromCharCode(bytes[i]);
                }
                return window.btoa(binary);
            }
        });
    });
</script>

</body>
</html>
